import { put, takeEvery, call } from "redux-saga/effects"
import { get } from "@/utils/axios"

function* handleGetList(action) {
    console.log("saga action 被拦截", action)
    try {
        console.log("发送get请求")
        const url = "https://easy-mock.com/mock/5cb31c49bd0927702544e6a8/test/news#!method=get"
        const res = yield call(get, url)

        if (res.success) {
            console.log("数据请求成功")
            yield put({
                type: "module-list/success-got-list",
                list: res.data
            })
        }
    } catch (err) {
        console.error("get list error", err)
    }
}

export default function* listSaga() {
    // 拦截对应的saga-action,并执行处理函数
    yield takeEvery("module-list/start-get-list", handleGetList)
}
